<include file="public@header" />
</head>
<body>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li class="active"><a href="{:url('menu/index')}">{:lang('ADMIN_MENU_INDEX')}</a></li>
        <li><a href="{:url('menu/add')}">{:lang('ADMIN_MENU_ADD')}</a></li>
        <li><a href="{:url('menu/lists')}">{:lang('ADMIN_MENU_LISTS')}</a></li>
    </ul>
    <form class="js-ajax-form" action="{:url('Menu/listOrder')}" method="post">
        <table class="table table-hover table-bordered table-list" id="menus-table">
            <thead>
            <tr>
                <th width="80">{:lang('SORT')}</th>
                <th width="50">ID</th>
                <th>{:lang('NAME')}</th>
                <th>操作</th>
                <th width="80">{:lang('STATUS')}</th>
                <th width="80">是否菜单</th>
                <th width="180">{:lang('ACTIONS')}</th>
            </tr>
            </thead>
            <tbody>
            {$category}
            </tbody>
            <tfoot>
            <tr>
                <th width="80">{:lang('SORT')}</th>
                <th width="50">ID</th>
                <th>{:lang('NAME')}</th>
                <th>操作</th>
                <th width="80">{:lang('STATUS')}</th>
                <th width="80">是否菜单</th>
                <th width="180">{:lang('ACTIONS')}</th>
            </tr>
            </tfoot>
        </table>
    </form>
</div>
<script src="__STATIC__/js/admin.js"></script>
<script>
    $(document).ready(function() {
        Wind.css('treeTable');
        Wind.use('treeTable', function() {
            $("#menus-table").treeTable({
                indent : 20
            });
        });
    });
    
	$(".table-list").on("change",".input-order",function(){
		var id = $(this).parents('tr').attr("data-id");
		var value = $(this).val();
		top.$loading.show();
		if(id != null && value != null){
			$.post("{:url('listOrder')}",{ids:id,value:value},function(data){
				top.$loading.hide();
			})
		}
	})
	
	$(".table-list").on("click",".fa-check",function(){
		var obj = $(this);
		var id = obj.parents('tr').attr("data-id");
		var type = obj.attr("data-type");
		top.$loading.show();
		$.post("{:url('status')}",{ids:id,value:0,type:type},function(data){
			obj.removeClass("fa-check");
			obj.addClass("fa-close");
			top.$loading.hide();
		})
	})
	
	$(".table-list").on("click",".fa-close",function(){
		var obj = $(this);
		var id = obj.parents('tr').attr("data-id");
		var type = obj.attr("data-type");
		top.$loading.show();
		$.post("{:url('status')}",{ids:id,value:1,type:type},function(data){
			obj.removeClass("fa-close");
			obj.addClass("fa-check");
			top.$loading.hide();
		})
	})
	if ($('a.js-iframe-post').length) {
	    Wind.use('artDialog', 'iframeTools', function () {
	        $('.js-iframe-post').on('click', function (e) {
	            e.preventDefault();
	            var _this = this,
	                $_this = $(_this);
	            var dialog_iframe = art.dialog.open($(this).prop('href'), {
	                ok: function () {
						var iframe = this.iframe.contentWindow;
						$form = iframe.$("form.js-ajax-form");
						var action = $form.attr('action');
						var query = $form.serialize();
						var fields = $form.serializeArray();
						var params = new Object(); 
						jQuery.each( fields, function(i, field){
							params[field.name] = field.value;
						});
						$.post(action,query,function(data){
							if (data.referer) {
	                            //返回带跳转地址
	                        	window.location.href = data.referer;
	                        } else {
	                        	if (data.code == 1) {
	                                art.dialog({
                                        content: data.msg,
										fixed: true,
							            lock: true,
							            background: "#CCCCCC",
							            opacity: 0,
                                        icon: 'succeed',
                                        ok: function () {
											var id = params.id;
											$fffs = $("#node-"+id).find("fff");
                                            $($fffs[0]).html(params.name);
											$($fffs[1]).html(params.app+"/"+params.controller+"/"+params.action);
											if(params.status==0){
												$("#node-"+id).find("i[data-type='status']").removeClass("fa-check").addClass("fa-close");
											}
											else if(params.status==1){
												$("#node-"+id).find("i[data-type='status']").removeClass("fa-close").addClass("fa-check");
											}
											dialog_iframe.close();
                                            return true;
                                        },
                                    });
	                            } else if (data.code == 0) {
	                                art.dialog({
	                                    content: data.msg,
										fixed: true,
							            lock: true,
							            background: "#CCCCCC",
							            opacity: 0,
	                                    icon: 'warning',
	                                    ok: function () {
	                                        this.title(data.info);
	                                        return true;
	                                    }
	                                });
	                            }
	                        }
						})
		                return false;
		            },
					okVal: "提交",
					cancel: function () {
						$_this.focus();
		                return true;
		            },
					cancelVal: "取消",
			        close: function () {
			            $_this.focus(); //关闭时让触发弹窗的元素获取焦点
			            return true;
			        },
					width:'900px',
					height:'400px',
					fixed: true,
					lock:true,
	                title: $_this.prop('title')
	            });
	        }).attr('role', 'button');
	
	    });
	}
</script>
</body>
</html>